Skip to content

feat - added vendor agnostic sonar backend#45

Open
Prathmesh2931 wants to merge 3 commits intoIOES-Lab:ros2from
Prathmesh2931:wgpu-sonar-backend
Open

feat - added vendor agnostic sonar backend#45
Prathmesh2931 wants to merge 3 commits intoIOES-Lab:ros2from
Prathmesh2931:wgpu-sonar-backend

Conversation

@Prathmesh2931
Copy link


Basic Info

Info Please fill out this column
Primary OS tested on Ubuntu 22.04
Robotic platform tested on Standalone sonar physics pipeline (Gazebo integration in follow-up)
Does this PR contain AI generated software? No
Was this PR description generated by AI software? No

Description of contribution in a few bullet points

  • Added sonar_compute_wgpu.hh defining a SonarComputeBackend abstract interface and WgpuComputeBackend implementation — the sensor can swap between CUDA, wgpu, and CPU backends at runtime via an SDF <compute_backend> parameter without recompiling
  • Added sonar_compute_wgpu.cc implementing the wgpu backend through a Rust static library over a stable C FFI boundary — GPU init failures fall back to CPU automatically without crashing the sensor
  • Added wgpu_backend/ — a Rust crate with three WGSL compute shaders implementing Choi et al. (2021) Algorithm 1, plus a cbindgen-generated C header that stays in sync with the Rust source automatically
  • Updated CMakeLists.txt to optionally invoke cargo build --release when cargo is present — if cargo is absent the existing CUDA build is completely unaffected
  • Existing sonar_calculation_cuda.cu and the CUDA path are untouched

Description of the physics pipeline

Three WGSL compute shaders implement Choi et al. (2021) Algorithm 1:

  • backscatter.wgsl — Eq. 14 (scatter amplitude per ray) + Eq. 8 (coherent phase summation across frequency bins). Uses fixed-point atomicAdd for parallel ray accumulation since WGSL has no native float atomics. Philox4x32-10 RNG (Salmon et al. 2011, same constants as CUDA curand) + Box-Muller transform generates the complex Gaussian speckle (ξ_xi + i·ξ_yi)/√2 per ray
  • matmul.wgsl — tiled 16×16 shared-memory GEMM for beam pattern correction W·P/sum(W), replacing cuBLAS SGEMM
  • fft.wgsl — Cooley-Tukey radix-2 FFT converting beam spectrum P_j(f) to time-domain echo p_j(t). Range maps as r = t·c/(2B)

wgpu selects Vulkan on Linux, Metal on macOS, and DirectX 12 on Windows — the same WGSL shaders run unchanged on any backend.

Description of how this change was tested

Validated on a standalone physics pipeline using the Blueview P900-90 sonar configuration from Choi et al. (2021) Table 1 (512 beams, 114 rays, 512 freq bins, B=2.95 kHz):

GPU              : NVIDIA GeForce RTX 3050 6GB Laptop GPU (Vulkan)
range resolution : 0.254 m/bin  (c=1500 m/s, B=2.95 kHz)
expected bin     : 39  (10 m floor, r = t·c/2B)
observed peak    : 39
result           : ✓ PASS (diff=0)
avg dispatch     : 11.1 ms/frame over 10 runs  (11.1% of 10 Hz budget)

The peak bin check validates the full pipeline end-to-end: scatter amplitude (Eq. 14) → phase sweep (Eq. 8) → FFT → range. A flat floor at 10 m must produce a peak at bin t = 10 × 2B/c = 39. Getting diff=0 confirms the frequency grid convention, phase accumulation, and FFT output indexing are all correct.

Rust crate builds clean with cargo build --release on Ubuntu 22.04.

Description of documentation updates required

No documentation updates at this stage. Usage notes for the <compute_backend> SDF parameter will be added once the hookup into MultibeamSonarSensor.cc is reviewed and merged.


Known limitations and follow-up work

  • MultibeamSonarSensor.cc is not yet wired to call the new backend — intentionally left for a follow-up PR once this interface is reviewed by maintainers
  • GPU FFT shader requires power-of-2 n_freq; rustfft crate integration for arbitrary sizes is planned as a follow-up
  • D(θ,φ) beam pattern and S(f) source spectrum are set to 1 in this PR (ideal beam, flat spectrum) — full values are applied through the matmul pass in a follow-up
  • MultibeamSonarSensor.cc integration not tested on Gazebo Harmonic locally (Ubuntu 22.04 constraint) — CI will validate on the target platform

Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
…n fallback logic

clean - unnecessary comment in CMakeList.txt

Signed-off-by: Prathmesh Atkale <atkaleprathmesh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant